#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 1712;
long long pw[100]={1};
long long x[2000];
void init()
{
	long long t = 2;
	for(int i = 1;i<=64;i++)
	{
		pw[i] = pw[i-1]*t;
	}
	int cnt = 0;
	
	for(int i = 1;cnt<=maxn;i++)
	{
		for(int j = i-2;j>=0;j--)
		{
			x[++cnt] = (pw[i]-1)-pw[j];
			//printf("%I64d\n",x[cnt]);
		}
	}
}
int main()
{
	init();
	int k;
	scanf("%d",&k);
	while(k--)
	{
		long long a,b,ans = 0;
		scanf("%I64d %I64d",&a,&b);
		for(int i = 1;i<=maxn;i++)
		{
			if(x[i]<=b&&x[i]>=a)
			{
				ans++;
			}
			if(x[i]>b) break;
		}
		printf("%I64d\n",ans);
	}
}
